package com.zecan.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.zecan.springcloud.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName FlowLimitController
 * @Description TODO
 * @date 2022/5/11 19:49
 * @Version 1.0
 */

@RestController
@Slf4j
public class FlowLimitController {

    @Resource
    private TestService testService;

    @GetMapping("/testA")
    public String testA() {
        testService.getTest();
        return "----testA";
    }

    @GetMapping("/testB")
    public String testB() {
        log.info(Thread.currentThread().getName() + ".... \t");
        return "----testB";
    }


    @GetMapping("/testD")
    public String testD() {
        /*try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        log.info("testD 测试RT");
        int i = 10/0;
        return "----testD";
    }


    @GetMapping("/testE")
    //设定的资源名==> blockHandler 填入方法名, 当错误时页面显示返回的数据
    @SentinelResource(value = "testE" , blockHandler = "blockHandlerTestE")
    public String testE(@RequestParam(value = "p1" , required = false) String p1,
                        @RequestParam(value = "p2" , required = false) String p2) {
        return "hotPoint....";
    }

    public String blockHandlerTestE(String p1, String p2, BlockException exception) {
        return "blockHandlerTestE";
    }
}
